1. Field of the Invention
The present invention relates generally to an improved data processing system and in particular to a method and apparatus for storing data. More particularly, the present invention relates to a computer implemented method, apparatus, and a computer usable program product for storing partially aligned data.
2. Description of the Related Art
Gating circuitry on a computer chip between registers inside the CPU and the address bus gives preference to certain locations in memory where access to the data is most efficient. If a particular register type, such as a floating point register, is used to load data from memory, the data should start only at certain addresses if access efficiency is to be maximized. The reason for this fact is that the connection of the registers to the address bus often ignores certain low order bits in order to reduce the number of gates. Accordingly, the register is blind to certain address locations within a memory. The blind spot can be different for different register types. In some cases, extra processor cycles are needed to access data lying in portions of memory to which the registers are blind. In some other cases, access to the blind spots in the memory is prohibited.
A set of data is usually stored in chunks, or subsets, of data. Each subset of data is stored at particular addresses within the memory. As used herein, a “set of data” is a contiguous sequence of data bytes. A “subset of data” is a contiguous sub-sequence of data bytes within a set of data. In contemporary programming languages, such as C and C++, a “set of data” is represented by a data structure, and a “subset of data” is represented by members within a data structure.
A set of data is aligned if no portion of a subset of the data is located in a blind spot in the memory. Likewise, a subset of data is aligned if no portion of the subset of data is located in a blind spot in the memory. A set of data is unaligned if any portion of any subset of data is located in a blind spot in the memory. A set of data is partially aligned if that set of data includes at least one subset of data for which no portion of that subset is in a blind spot of the registers of the central processing unit. A set of data is poorly partially aligned if relatively few subsets of data of a set of data are aligned. A set of data is partially aligned well if relatively many subsets of data of a set of data are aligned.
In terms of high level programming languages, the phenomenon of blind spots in a memory for a processor can lead to requirements or restrictions on how variables defined in the programming language are best allocated in memory. These requirement or restrictions can be referred to as an alignment paradigm. The alignment paradigm is specific to the processor architecture of the computer being used.
Because lower order lines are ignored by addressing, alignment usually manifests itself as aligning data on multiple powers of two. Optimizing compilers for high level languages often take into account this fact when allocating variables.
Traditionally, alignment of all subsets of data is achieved by assuming the base address of the structure is zero, mapping the next subset of data onto the next available non-blind spot in memory, and then leaving gaps within the structure, if needed. When allocating the structure variable, the structure variable is aligned according to the most stringent requirements of all subsets of data. All subsets of data will then be aligned properly. The set of data is then aligned, resulting in maximum processor efficiency when accessing the set of data or any subset of data.
A structure or structure variable is a contiguous data block in memory. The block is divided into data fields called members. In this description, the data block is also referred to as set of data, and the data field as a subset of data.
However, this method of storing data is not always possible or desirable. For example, when a set of data is transported over a network the set of data is often compacted as tightly as possible. Data compacted for transfer over a network is most often poorly partially aligned and is sometimes unaligned. Additionally, when data is exchanged between two processes running on two different hardware architectures, the data must be organized or stored according to predetermined methods.
As a result, the set of data may be poorly partially aligned. Accordingly, a process may function less efficiently or not at all. As a result, performance of a process, software, or machine, in terms of the time required to execute a process, can be substantially reduced, often by a factor of ten or more.